﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TFXK.BLL;
using TFXK.Common;
using log4net;
using TFXK.Model;

public partial class HotelList : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private static readonly CategoryBLL bllCategory = new CategoryBLL();
    private static readonly HotelBLL bllHotel = new HotelBLL();
    public Category model = new Category();
    int count = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
        }
    }

    #region 分页绑定
    private void InitData(int PageIndex)
    {
        DataSet ds = new DataSet();
        string title = string.Empty;
        string cityName = string.Empty;
        string tourName = string.Empty;

        int city = 0;
        int type = 0;
        if (Request.QueryString["SKey"] != null)
        {
            try
            {
                title = StringUtil.HtmlEncode(Request.QueryString["SKey"] + "");
            }
            catch
            {
            }
        }

        if (Request.QueryString["CID"] != null)
        {
            try
            {
                city = int.Parse(Request.QueryString["CID"] + "");
            }
            catch
            {
                city = 0;
            }
        }


        if (Request.QueryString["TID"] != null)
        {
            try
            {
                type = int.Parse(Request.QueryString["TID"] + "");
            }
            catch
            {
                type = 0;
            }
        }


        if (Request.QueryString["City"] != null)
        {
            try
            {
                cityName = StringUtil.HtmlEncode(Request.QueryString["City"] + "");
            }
            catch
            {
                cityName = "";
            }
        }
        if (Request.QueryString["Tour"] != null)
        {
            try
            {
                tourName = StringUtil.HtmlEncode(Request.QueryString["Tour"] + "");
            }
            catch
            {
                tourName = "";
            }
        }

        if (!string.IsNullOrEmpty(tourName))
        {
            ds = bllHotel.GetListByTourName(AspNetPager1.PageSize, PageIndex, tourName, out count);
        }
        else if (cityName != "")
        {
            ds = bllHotel.GetListByCityName(AspNetPager1.PageSize, PageIndex, cityName, out count);
        }
        else
        {
            ds = bllHotel.GetList(AspNetPager1.PageSize, PageIndex, title, type, city, out count);
        }


        AspNetPager1.RecordCount = count;

        this.rptContent.DataSource = ds.Tables[0].DefaultView;
        this.rptContent.DataBind();
    }
    #endregion

    #region 分页控件加载
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                InitData(e.NewPageIndex);
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
        }
    }
    #endregion

    #region 设置图片
    public string GetPic(object obj)
    {
        try
        {
            if (string.IsNullOrEmpty(obj + ""))
            {
                obj = "images/nopic.jpg";
            }
            else
            {
                obj = "uploads/" + obj;
            }
        }
        catch
        {
            obj = "images/nopic.jpg";
        }

        return obj + "";
    }
    #endregion

    //设置星级
    public string SetStarWidth(object obj)
    {
        try
        {
            int num = int.Parse(obj + "");
            return num * 12 + "";
        }
        catch
        {
            return "0";
        }
    }
}
